package org.zjx.core.builder;

import org.zjx.core.DecisionNode;
import org.zjx.core.GameAction;
import org.zjx.core.nodes.ActionNode;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public class ActionBuilder {
    private final String actionId;
    private final Map<String, Object> params = new HashMap<>();
    private DecisionNode next;

    public ActionBuilder(String actionId) {
        this.actionId = actionId;
    }

    public ActionBuilder param(String key, Object value) {
        params.put(key, value);
        return this;
    }

    public ActionBuilder next(Consumer<DecisionTreeBuilder> config) {
        DecisionTreeBuilder builder = new DecisionTreeBuilder();
        config.accept(builder);
        this.next = builder.build();
        return this;
    }

    public DecisionNode build() {
        GameAction action = new SimpleGameAction(actionId, params);
        return new ActionNode(action, next);
    }
}